package com.lgd.factoryattendance.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.lgd.factoryattendance.Bean.ElectricSpinnerBean;
import com.lgd.factoryattendance.Bean.MachineSpinnerBean;
import com.lgd.factoryattendance.R;

import java.util.List;

/**
 * @Author lgd
 * @Date 2024/7/8 14:57
 */
public class MachineSpinnerAdapter extends BaseAdapter {
    private Context context;
    List<MachineSpinnerBean> machineSpinnerBeanList;
    private LayoutInflater layoutInflater;

    public MachineSpinnerAdapter(Context context, List<MachineSpinnerBean> machineSpinnerBeanList) {
        this.context = context;
        this.machineSpinnerBeanList = machineSpinnerBeanList;
        this.layoutInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return machineSpinnerBeanList == null ? 0 : machineSpinnerBeanList.size();
    }

    @Override
    public Object getItem(int position) {
        return machineSpinnerBeanList == null ? null : machineSpinnerBeanList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null){
            convertView = layoutInflater.inflate(R.layout.electric_spinner_custom, parent, false);
            holder = new ViewHolder();
            holder.tv_machineName = convertView.findViewById(R.id.tv_electricName);
            convertView.setTag(holder);
        }else {
            holder = (ViewHolder)convertView.getTag();
        }
        MachineSpinnerBean machineSpinnerBean = machineSpinnerBeanList.get(position);
        holder.tv_machineName.setText(machineSpinnerBean.getMachineAssemblyName());
        return convertView;
    }

    static class ViewHolder {
        TextView tv_machineName;
    }

}
